package com.map.station;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class DetailActivity extends Activity{

	private Cursor cursor;
	private String keySearch = null;
	
	static Bundle bundle = new Bundle();
	
	Intent intent;
	
	private TextView brand, detail, latitude, longitude;
	private Button route;
	
	private String lat, lng;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newdetail);
		
		DBAdapter db = new DBAdapter(this);
		
		//get value
		final Bundle bundle = this.getIntent().getExtras();
		String name = bundle.getString("stationKeyword");
		int index = bundle.getInt("indexKeyword");
		
		brand = (TextView)findViewById(R.id.stationName);
		detail = (TextView)findViewById(R.id.detail);
		latitude = (TextView)findViewById(R.id.latitude);
		longitude = (TextView)findViewById(R.id.longitude);
		route = (Button)findViewById(R.id.rounting);
		
		db.open();
		
		if(name.equalsIgnoreCase("shell") || name.equalsIgnoreCase("proserv")) {
			if(index == 0)
				keySearch = "7.88599";
			else if(index == 1)
				keySearch = "7.88291";
			else if(index == 2 || index == 4 || index == 5)
				keySearch = "7.868459";
			else if(index == 3 || index == 6) {
				keySearch = "7.90827";
			}
		} else if(name.equalsIgnoreCase("bcp")){
				keySearch = "7.807598";
		}else if(name.equalsIgnoreCase("caltex")) {
			if(index == 0)
				keySearch = "8.02331";
		} else if(name.equalsIgnoreCase("esso") || name.equalsIgnoreCase("tiger mart")) {
			if(index == 1)
				keySearch = "7.89017";
			else if(index == 2)
				keySearch = "7.8789";
			else if(index == 3)
				keySearch = "7.89796";
			else if(index == 0 || index == 4)
				keySearch = "7.90199";
		} else if(name.equalsIgnoreCase("ptt") || name.equalsIgnoreCase("seven eleven")) {
			if(index == 0)
				keySearch = "7.91028";
			else if(index == 1) {
				keySearch = "7.87872";
			} else if(index == 2) {
				keySearch = "7.842094";
			}
		} else if(name.equalsIgnoreCase("sptt")){
			if(index == 1) {
				keySearch = "7.91028";
			} else if(index == 2) {
				keySearch = "7.87872";
			} else if(index == 3) {
				keySearch = "7.842094";
			}
		} else if(name.equalsIgnoreCase("tiny coffee")) {
			if(index == 0)
				keySearch = "7.88291";
			else if(index == 1)
				keySearch = "7.868459";
			else
				keySearch = "7.90827";
		} else if(name.equalsIgnoreCase("kbank atm") || name.equalsIgnoreCase("ktb bank")) {
			keySearch = "7.868459";
		} else if(name.equalsIgnoreCase("vesso")) {
			keySearch = "7.90199";
		} else if(name.equalsIgnoreCase("vptt")) {
			keySearch = "7.91028";
		} else if(name.equalsIgnoreCase("vshell")) {
			if(index == 0) {
				keySearch = "7.868459";
			} else if(index == 1) {
				keySearch = "7.90827";
			}
		}
		
		cursor = db.getSpecial(keySearch);
		if(cursor.moveToFirst()) {
			SetDetail(cursor);
		}
		else
			Toast.makeText(this, "ERROR", Toast.LENGTH_LONG).show();
		db.close();
		
		//set Route Button
		route.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				lng = cursor.getString(2);
				lat = cursor.getString(3);
				
				intent = new Intent(getBaseContext(), RouthPath.class);
				bundle.putString("passLatitude", lat);
				bundle.putString("passLongitude", lng);
				intent.putExtras(bundle);
				startActivity(intent);
			}
		});
	}
	
	//show description
	public void SetDetail(Cursor cursor) {
		brand.setText(cursor.getString(1));
		latitude.setText("Longitude : "+cursor.getString(2));
		longitude.setText("Latitude : "+cursor.getString(3));
		detail.setText("Detail : "+cursor.getString(6));
	}
}
